<template>
  <div>
    <el-card>
      <div slot="header">
        <span>订单管理</span>
      </div>
      <div class="formBox">
        <el-form
          :inline="true"
          size="small"
          ref="searchForm"
          :model="searchForm"
        >
          <el-form-item label="订单号" prop="orderNo">
            <el-input
              placeholder="请输入订单号"
              v-model="searchForm.orderNo"
            ></el-input>
          </el-form-item>
          <el-form-item label="收货人" prop="consignee">
            <el-input v-model="searchForm.consignee"></el-input>
          </el-form-item>
          <el-form-item label="手机号" prop="phone">
            <el-input v-model="searchForm.phone"></el-input>
          </el-form-item>
          <el-form-item label="订单状态" prop="orderState">
            <el-select v-model="searchForm.orderState">
              <el-option value="待处理">待处理</el-option>
              <el-option value="已受理">已受理</el-option>
              <el-option value="派送中">派送中</el-option>
              <el-option value="已完成">已完成</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="下单时间" prop="date">
            <el-date-picker
              v-model="searchForm.date"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchSubmit">查询</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="order-body">
        <el-table :height="310" :data="tableData" border style="width: 100%">
          <el-table-column fixed prop="orderNo" label="订单号" width="150">
          </el-table-column>
          <el-table-column label="下单时间" width="200">
            <template slot-scope="scope">
              <span>{{ scope.row.orderTime | handeTime }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="phone" label="联系电话" width="120">
          </el-table-column>
          <el-table-column prop="consignee" label="收货人" width="120">
          </el-table-column>
          <el-table-column prop="deliverAddress" label="配送地址" width="300">
          </el-table-column>
          <el-table-column prop="deliveryTime" label="送达时间" width="200">
          </el-table-column>
          <el-table-column prop="remarks" label="用户备注" width="300">
          </el-table-column>
          <el-table-column prop="orderAmount" label="订单金额" width="120">
          </el-table-column>
          <el-table-column prop="orderState" label="订单状态" width="120">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click="toMore(scope.row.id, 1)"
                >查看</el-button
              >
              <el-button
                type="text"
                size="small"
                @click="toMore(scope.row.id, 2)"
                >编辑</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="pageBox">
          <el-pagination
            @current-change="currentChange"
            :page-size="5"
            layout="total, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import { $_order_list } from "@/api/order";
import { handeTime } from "@/utils/date";
export default {
  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address1: "上海市普陀区金沙江路 1518 弄",
          address2: "上海市普陀区金沙江路 1518 弄",
          address3: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address1: "上海市普陀区金沙江路 1517 弄",
          address2: "上海市普陀区金沙江路 1518 弄",
          address3: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address1: "上海市普陀区金沙江路 1519 弄",
          address2: "上海市普陀区金沙江路 1518 弄",
          address3: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address1: "上海市普陀区金沙江路 1516 弄",
          address2: "上海市普陀区金沙江路 1518 弄",
          address3: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
      ],
      currentPage: 1,
      pageSize: 5,
      total: 0,
      searchForm: {
        orderNo: "",
        consignee: "",
        phone: "",
        orderState: "",
        date: [],
      },
    };
  },
  created() {
    // 进入页面就请求订单列表数据
    this.getData();
  },
  methods: {
    getData() {
      $_order_list({
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        ...this.searchForm,
        date: JSON.stringify(
          this.searchForm.date == null ? [] : this.searchForm.date
        ),
      }).then((res) => {
        this.total = res.data.total;

        this.tableData = res.data.data;
        this.tableData.forEach(
          (item) => (item.deliveryTime = handeTime(item.deliveryTime))
        );
        console.log(154, this.tableData);
      });
    },
    // 分页切换
    currentChange(page) {
      this.currentPage = page;
      this.getData();
    },
    // 查询
    searchSubmit() {
      console.log(this.searchForm);
      this.currentPage = 1;
      this.getData();
    },
    resetForm() {
      this.$refs.searchForm.resetFields();
    },
    // 跳转到订单详情页面
    toMore(id, type) {
      this.$router.push({
        path: "/Order/OrderMore",
        query: {
          type,
          id,
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.el-input {
  width: 200px;
}
.el-select {
  width: 200px;
}
.pageBox {
  margin-top: 20px;
}
</style>